package cn.ppool.xmlmapper.init;

import cn.ppool.xmlmapper.builder.MapperBuilder;
import cn.ppool.xmlmapper.utils.BeanUtil;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;

import java.util.*;


public class Configure implements ImportBeanDefinitionRegistrar, ResourceLoaderAware {

    private ResourceLoader resourceLoader;

    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        List<Object> configureConstructorArg = Arrays.asList(registry, resourceLoader);
        BeanUtil.registerBean(registry, MapperBuilder.class, "configure", new HashMap<>(), configureConstructorArg);
    }


    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }
}
